<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('银河票务商品详情')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-project-detail" th:object="${projectDetail}">
			<input id="projectToken" name="projectToken"  type="hidden" th:field="*{projectToken}" />
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">商品名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="projectName" id="projectName" th:field="*{projectName}" required disabled>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">站点：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="siteName" id="siteName" th:field="*{siteName}" required disabled>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">用户：</label>
				<div class="col-sm-8">
					<select id="userId" class="form-control m-b" name="userId" required>
						<option th:each="user:${userList}" th:value="${user.userId}" th:text="${user.userAccount}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">场次：</label>
				<div class="col-sm-8">
					<select id="eventToken" class="form-control m-b" name="eventToken" required>
						<option value="">请选择</option>
						<option th:each="event:${projectDetail.eventVoList}" th:value="${event.eventToken}" th:text="${event.eventCaption}"></option>
					</select>
				</div>
				<label class="col-sm-3 control-label is-required">票档：</label>
				<div class="col-sm-8">
					<select id="priceId" name="priceId" class="form-control m-b" required>
						<option value="">请选择</option>
					</select>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "galaxy/project";
	
		$("#eventToken").bind("change", function () {
			$('#priceId option').not('option:first').remove();
			let userId = $("#userId").val();
			const eventToken = $("#eventToken option:selected").val();
			if (eventToken === "") {
				return;
			}
			$.ajax({
				type: 'get',
				url: prefix + '/event/' + eventToken + "/" + userId,
				dataType:'json',
				success: function (data) {
					if (data.code !== null && data.code !== undefined && data.code !== 200) {
						alert(data.msg);
					}
					let priceVoList = data["priceVoList"];
					for (let i = 0; i < priceVoList.length; i++) {
						let vo = priceVoList[i];
						$("#priceId").append("<option value=" + vo.priceId + ">" + vo.priceName + "(" + vo.price + ")" + "</option>");
					}
				}
			})
		});

		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(ctx + "galaxy/trade/placeOrder", $('#form-project-detail').serialize());
	        }
	    }
	</script>
</body>
</html>
